package cn.faifai.tagapi.service.BackgroundServices.FileWatcher;

import cn.faifai.tagapi.service.BackgroundServices.FileWatcher.impl.WindowsRecycleBinFileWatcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class FileWatcherFactory implements ApplicationContextAware {

    private static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        context = applicationContext;
    }

    public FileWatcherService getFileWatcher() {
        String osName = System.getProperty("os.name").toLowerCase();
        return this.getFileWatcher(osName);
    }

    public FileWatcherService getFileWatcher(String osName) {
        osName = osName.toLowerCase();
        if (osName.contains("win")) {
            return context.getBean(WindowsRecycleBinFileWatcher.class);
        } else if (osName.contains("nix") || osName.contains("nux") || osName.contains("mac")) {
//            return new LinuxFileIdFetcher();
            return null;
        } else {
            throw new UnsupportedOperationException("Unsupported operating system: " + osName);
        }
    }
}
